var setting = {
	'verifyCodeUrl' : '/authority/authImage',
	'login_msg' : '登录',
	'ableClick' : false,
	loginIcon: 'time',
    rules: {
        user_name: [
            { required: true, message: '用户名不能为空', trigger: 'blur'}
        ],
        password: [
            { required: true, message: '密码不能为空', trigger: 'blur'}
        ],
        verifyCode: [
            { required: true, message: '验证码不能为空', trigger: 'blur'}
        ]
    },
	ruleForm: {
        verifyCode : '',
        user_name : '',
        password : '',
	}
}
var vue = new Vue({
	el: '.login',
	data: setting,
	methods:{
        getVerifyCode: function () {
			this.verifyCodeUrl =  '/authority/authImage?'+(Math.random())
        },
		login: function () {
            vue.$refs['ruleForm'].validate(function (v) {
            	if(v){
                    var data = vue.ruleForm;
                    vue.login_msg = '登录中...';
                    vue.ableClick = true;
                    vue.loginIcon = 'loading';
                    $.post('/authority/login',data,function (msg) {

                        if(msg.status == 'SUCCESS'){
                            location.href = '/index.html'
                        }else {
                            vue.$message({
                                message: msg.message,
                                type: 'warning'
                            });
                            vue.login_msg = '登录';
                            vue.loginIcon = 'time';
                            vue.ableClick = false;
                            vue.getVerifyCode();
                        }
                    })
				}
			})
        }
	}
})